package com.yyw.springboot02web.controller;

import org.springframework.stereotype.Controller;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpSession;
import java.util.Map;

/**
 * @ClassName LoginController
 * @Description TODO
 * @Author YiYuWei
 * @Date 2020/6/27 11:10
 * @Version 1.0
 */
@Controller
@RequestMapping("/user")
public class LoginController {
    @PostMapping("/login")
    public String login(@RequestParam("username") String username,
                        @RequestParam("password") String password,
                        Map<String,Object> map, HttpSession session){
        if (!StringUtils.isEmpty(username) && !StringUtils.isEmpty(password)
            && "123456".equals(password) && "admin".equals(username)){
            session.setAttribute("user",username);
            return "redirect:/main.html";
        }
        map.put("msg","用户名或密码错误");
        return "/index.html";
    }
}
